function render(list) {
  let oForm = document.querySelector("form")
  for (let i in list) {
    let track = list[i]
    let oLabel = document.createElement('label')
    let oCheckbox = document.createElement('input')
    oCheckbox.type = 'checkbox'
    oCheckbox.name = 'tid'
    oCheckbox.value = 't' + track.tid
    oLabel.appendChild(oCheckbox)
    oLabel.appendChild(document.createTextNode(track.title))
    oForm.appendChild(oLabel)
  }
}

window.addEventListener('load', function () {let aid = getParameter("aid")
  if (isNaN(aid)) {
    alert("url 中没有 aid 或者 aid 不是数字")
    return
  }

  document.querySelector("#aid").value = aid

  let xhr = new XMLHttpRequest()
  xhr.open('get', '/studio/album/candidate-list.json?aid=' + aid)
  xhr.addEventListener('load', function () {
    console.log(xhr.responseText)
    let data = JSON.parse(this.responseText)
    renderCurrentUser(data.currentUser)
    if (data.trackList) {
      render(data.trackList)
    }
  })
  xhr.send()
})